package com.hotel.management.entity;

import com.fasterxml.jackson.annotation.JsonFormat;


import javax.persistence.*;
import javax.validation.constraints.*;
import java.util.Date;

/**
 * 员工实体类
 * 
 * @author Hotel Management Team
 * @version 1.0.0
 * @since 2024-06-28
 */
@Entity
@Table(name = "employee", 
       indexes = {
           @Index(name = "idx_employee_name", columnList = "name"),
           @Index(name = "idx_employee_position", columnList = "position"),
           @Index(name = "idx_employee_status", columnList = "status"),
           @Index(name = "idx_employee_role_id", columnList = "role_id")
       })
public class Employee extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 员工编号
     */
    @NotBlank(message = "员工编号不能为空")
    @Size(min = 3, max = 20, message = "员工编号长度必须在3-20个字符之间")
    @Column(name = "employee_no", nullable = false, unique = true, length = 20, columnDefinition = "VARCHAR(20) COMMENT '员工编号'")
    private String employeeNo;

    /**
     * 员工姓名
     */
    @NotBlank(message = "员工姓名不能为空")
    @Size(min = 2, max = 50, message = "员工姓名长度必须在2-50个字符之间")
    @Column(name = "name", nullable = false, length = 50, columnDefinition = "VARCHAR(50) COMMENT '员工姓名'")
    private String name;

    /**
     * 性别 (男/女)
     */
    @NotBlank(message = "性别不能为空")
    @Pattern(regexp = "^(男|女)$", message = "性别只能是'男'或'女'")
    @Column(name = "gender", nullable = false, length = 2, columnDefinition = "VARCHAR(2) COMMENT '性别'")
    private String gender;

    /**
     * 年龄
     */
    @NotNull(message = "年龄不能为空")
    @Min(value = 18, message = "年龄不能小于18岁")
    @Max(value = 65, message = "年龄不能大于65岁")
    @Column(name = "age", nullable = false, columnDefinition = "INT COMMENT '年龄'")
    private Integer age;

    /**
     * 手机号码
     */
    @NotBlank(message = "手机号码不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号码格式不正确")
    @Column(name = "phone", nullable = false, length = 11, unique = true, 
            columnDefinition = "VARCHAR(11) COMMENT '手机号码'")
    private String phone;

    /**
     * 邮箱地址
     */
    @NotBlank(message = "邮箱地址不能为空")
    @Email(message = "邮箱地址格式不正确")
    @Size(max = 100, message = "邮箱地址长度不能超过100个字符")
    @Column(name = "email", nullable = false, length = 100, unique = true,
            columnDefinition = "VARCHAR(100) COMMENT '邮箱地址'")
    private String email;

    /**
     * 入职日期
     */
    @NotNull(message = "入职日期不能为空")
    @Past(message = "入职日期不能是未来时间")
    @Column(name = "hire_date", nullable = false, columnDefinition = "DATE COMMENT '入职日期'")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @Temporal(TemporalType.DATE)
    private Date hireDate;

    /**
     * 职位
     */
    @NotBlank(message = "职位不能为空")
    @Size(min = 2, max = 30, message = "职位名称长度必须在2-30个字符之间")
    @Column(name = "position", nullable = false, length = 30, columnDefinition = "VARCHAR(30) COMMENT '职位'")
    private String position;

    /**
     * 角色ID (关联角色表)
     */
    @NotNull(message = "角色ID不能为空")
    @Column(name = "role_id", nullable = false, columnDefinition = "BIGINT COMMENT '角色ID'")
    private Long roleId;

    /**
     * 员工状态 (在职/离职/休假)
     */
    @NotBlank(message = "员工状态不能为空")
    @Pattern(regexp = "^(在职|离职|休假)$", message = "员工状态只能是'在职'、'离职'或'休假'")
    @Column(name = "status", nullable = false, length = 10, columnDefinition = "VARCHAR(10) DEFAULT '在职' COMMENT '员工状态'")
    private String status = "在职";

    /**
     * 默认构造函数
     */
    public Employee() {
        super();
    }

    /**
     * 带参数的构造函数
     */
    public Employee(String name, String gender, Integer age, String phone, String email, 
                   Date hireDate, String position, Long roleId) {
        this();
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.phone = phone;
        this.email = email;
        this.hireDate = hireDate;
        this.position = position;
        this.roleId = roleId;
    }

    // Getter and Setter methods
    public String getName() {
        return name;
    }

    public String getEmployeeNo() {
        return employeeNo;
    }

    public void setEmployeeNo(String employeeNo) {
        this.employeeNo = employeeNo;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getHireDate() {
        return hireDate;
    }

    public void setHireDate(Date hireDate) {
        this.hireDate = hireDate;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}
